home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
- import sub_arctic.input.*;
- import sub_arctic.output.style;
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.style_manager;
-
- import java.awt.Point;
- import java.awt.Font;
- /*
- * This class implements a button which can pop up a menu when
- * pressed on.
- *
- * @author Ian Smith
- */
- public class menu_button
- extends multi_button implements pressable, menu_notifier {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The x spacing for this object.
- */
- protected int _x_spacing=10;
-
- /**
- * Get the x spacing.
- * @return int the amount of x spacing
- */
- public int x_spacing() { return _x_spacing;}
-
- /**
- * Set the x spacing.
- * @param int x the new value for the x spacing
- */
- public void set_x_spacing(int x) {
- _x_spacing=x;
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The y spacing for this object.
- */
- protected int _y_spacing=5;
-
- /**
- * Get the y spacing.
- * @return int the amount of y spacing
- */
- public int y_spacing() { return _y_spacing;}
-
- /**
- * Set the y spacing.
- * @param int y the new value for the y spacing
- */
- public void set_y_spacing(int y) {
- _y_spacing=y;
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This holds a pointer to our menu that we will pop up.
- */
- menu _menu;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function is called in response to a press method.
- * @param event e the event to dispatch (the mouse down).
- * @param Object user_info (currently ignored) the object passed to the
- * pick_collector at pick-time.
- * @return boolean true if this event was dispatched.
- */
- public boolean press(event e, Object user_info /* ignored */) {
- style cs=style_manager.current_style();
-
- /* make us change state */
- set_cur_state(1);
-
- /* get a top level and get the top left point of our rectangle
- in its coord sys */
- top_level tl=get_top_level();
- Point p=new Point(0,0);
- p=local_to_global(p);
-
- /* put the new menu in the toplevel at the right spot */
- /* test for pop down or pop right */
- if (cs.menu_pop_right()) {
- _menu.set_x(p.x+w());
- _menu.set_y(p.y);
- } else {
- _menu.set_x(p.x);
- _menu.set_y(p.y+h());
- }
-
- tl.add_child(_menu);
- menu.agent().set_focus_to(_menu,e,null,this); /* no user info for now */
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /*
- * This never gets called because we make the other object the
- * menu drag focus.
- *
- * @param event e the event to dispatch.
- * @param Object user_info (currently ignored) the object passed to the
- * pick_collector at pick-time.
- * @return boolean true if this event was dispatched.
- */
- public boolean release(event e, Object user_info /*ignored */) {
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The text string on this object.
- */
- protected String _text;
-
- /**
- * Retrieve the text value on this object.
- * @return String the text on this menu button
- */
- public String text() { return _text;}
-
- /**
- * Set the text of this object.
- * @param String t the new text to display on this menu button
- */
- public void set_text(String t) {
- _text=t;
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The font for this object.
- */
- protected Font _font=null;
-
- /**
- * Get the font associated with this object. This will return the
- * system's default font if you haven't set the font.
- * @return Font the font used to display this menu button's text
- */
- Font font() {
- if (_font==null) {
- return style_manager.default_font();
- } else {
- return _font;
- }
- }
-
- /**
- * Set the font associated with this object. If you set the font
- * to null, you'll get the system default font.
- * @param Font f the new font
- */
- public void set_font(Font f) {
- _font=f;
- style_changed();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Redraw the images for this menu button.
- */
- protected void style_changed() {
- loaded_image[] img;
- img=style_manager.current_style().button_make_images(text(),
- font(),
- x_spacing(),
- y_spacing(),
- true);
- set_looks(img,null);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a menu button given a string. We assume you will use
- * constraints (or direct setting) to position this object.
- * @param String s the string to display on the menu button.
- * @param menu m the menu to pop up when the button is pressed.
- */
- public menu_button(String s, menu m) {
- super(0,0,null,null,null);
- _menu=m;
- set_text(s);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a menu button given a string and a given font.
- * We assume you will use constraints to position this object
- * or set the position directly.
- *
- * @param String s the string to display on the menu button.
- * @param Font f font we draw labels in.
- * @param menu m the menu to pop up when the button is pressed.
- */
- public menu_button(String s,Font f, menu m){
- super(0,0,null,null,null);
- _font=f;
- _menu=m;
- set_text(s);
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This method gets called by the menu_agent to inform us that
- * the interaction is completed.
- */
- public void menu_done() {
- /* set our look to the up state ... just to make sure */
- set_cur_state(0);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This function is called to alert the notifier that the interaction
- * is now over their area. The notifier should return true if it
- * modified the set of objects in the menu focus in response to
- * this call. Menu_buttons don't use this call and always return false.
- *
- * @param int x the x coordinate (in the notifiers coordinate system) of
- * the cursor.
- * @param int y the y coordinate (in the notifiers coordinate system) of
- * the cursor.
- * @param event evt the event we are testing.
- * @return boolean true if the notifier modified the focus set of the menu
- * agent in response to this.
- */
- public boolean menu_modify(int x,int y, event evt) { return false;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-